<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--导入热处理模态框-->
<div class="modal fade" id="modal-import">
    <div class="modal-dialog" style="width:600px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">导入机加工时</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>模版</label>
                        <a th:href="@{/file/核算数据导入机加工时模板.xlsx}">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>上次导入错误数据</label>
                        <a id="download-error"
                           th:data-url="@{/files/{user}/accErrorMachiningHours.xlsx(user=${session.user.account})}"
                           href="javascript:void(0);">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input class="btn" type="file" multiple="multiple" name="file">
                        <p class="help-block">请按模板格式进行导入，信息与模板信息对应。</p>
                        <input type="hidden" style="display: none" name="batId" th:value="${batId}"/>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info file-contract btn-file"
                        id="btn-save-import">保存
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>

        </div>
    </div>
</div>
<section class="content-header">
    <h1 style="display: inline-block">机加工时导入</h1>
    <a href="javascript:window.history.back();" type="button"
       class="btn btn-success"
       style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
        <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
           class="glyphicon glyphicon-share-alt"></i><span
            style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
    </a>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="row">
                        <div class="form-inline" style="border-bottom: 3px #D2D6DE solid;">
                            <div class="form-group">
                                <label class="control-label">
                                    项目编号：
                                </label>
                                <label class="control-label" th:text="${project.code}"></label>
                                <input id="code" type="hidden" th:value="${project.code}" style="display: none">
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    项目名称：
                                </label>
                                <label class="control-label" th:text="${project.name}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    需方：
                                </label>
                                <label class="control-label" th:text="${project.demander}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    安装地点：
                                </label>
                                <label class="control-label" th:text="${project.address}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    项目数量：
                                </label>
                                <label class="control-label" th:text="${project.num}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    设计类别：
                                </label>
                                <label class="control-label"
                                       th:text="${project.projectClassify == 1 ? '设计':'非设计'}"></label>
                            </div>

                        </div>
                    </div>
                    <div class="col-sm-12">
                        <form id="queryForm" class="form-horizontal">
                            <input type="hidden" style="display: none" name="batId" th:value="${batId}"/>
                            <input type="hidden" style="display: none" name="type" value="2"/>
                            <div class="row">
                                <div class="form-inline">
                                    <div class="form-group" style="padding-right: 10px;">
                                        <label class="control-label">
                                            部分：
                                        </label>
                                        <label class="control-label">
                                            <input name="part" class="form-control" type="text"/>
                                        </label>
                                    </div>
                                    <div class="form-group" style="padding-right: 10px;">
                                        <label class="control-label">
                                            专业：
                                        </label>
                                        <label class="control-label">
                                            <select name="majors" class="form-control">
                                                <option value="'机械','流体','自动化'">全部</option>
                                                <option value="'机械'">机械</option>
                                                <option value="'流体'">流体</option>
                                                <option value="'自动化'">自动化</option>
                                            </select>
                                        </label>
                                    </div>

                                    <div class="form-group pull-right">
                                        <label class="control-label">
                                            <button id="btn-search" style="margin-top: 4px" type="button"
                                                    class="btn btn-success">搜索
                                            </button>
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div id="toolBar">
                    <button id="btn-batch-delete" class="btn btn-danger">
                        批量删除
                    </button>
                    <button id="btn-import-import" class="btn btn-info">
                        导入
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table;
    $(function () {
        /** 导入表单验证 */
        js.validate.init("importForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'},
                        file: {extension: 'xls,xlsx', message: '请选择excel文件'}
                    }
                }
            }
        });
        /** 导入模态框隐藏事件 */
        js.modal.hideEvent("modal-import", function () {
            js.validate.reset("importForm");
            $("#importForm [name='file']").val(null);
        });
        /** 下载导入失败excel */
        $("#download-error").click(function () {
            var that = $(this);
            js.post({
                url: ctx + "accountingInfo/exist",
                async: false,
                data: {
                    url: that.attr("data-url")
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        that.attr("href", that.attr("data-url") + "?timeStamp=" + new Date().getTime());
                    } else {
                        js.modal.warning("没有需要处理的文件");
                    }
                }
            });
        });
        /** 导入 */
        $("#btn-save-import").click(function () {
            js.modal.confirm("尊敬的用户，您确认要导入数据吗？", function () {
                var $this = $(this);
                $this.attr('disabled', true);
                js.validSubmit({
                    formId: "importForm",
                    url: ctx + "accountingInfo/accMachiningHoursImport",
                    data: new FormData($("#importForm")[0]),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            debugger
                            js.modal.alert(result.msg);
                            if (result.msg == '导入完成') {
                                js.modal.hide("modal-import");
                                js.table.refresh(table);
                            }
                            $this.attr('disabled', false);
                        }
                    }
                });
            })
        });
        /**
         * 打开导入外购件模态框
         */
        $("#btn-import-import").on('click', function () {
            js.modal.open("modal-import");
        });
        /**
         * 搜索
         */
        $("#btn-search").on('click', function () {
            js.table.refresh(table);
        });
        /**
         * 批量删除
         */
        $("#btn-batch-delete").on('click', function () {
            let arr = js.table.selectColumns(table, "id");
            let idStr = arr.join(',');
            if (idStr === '') {
                js.modal.warning("尊敬的用户，请您选择要删除的数据！");
                return;
            }
            js.post({
                url: ctx + 'accountingInfo/removeBusMachiningHoursByIds',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    ids: idStr
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                },
                error: function () {
                    js.modal.fail();
                }
            });
        });
        table = js.table.init({
            queryForm: 'queryForm',
            url: ctx + "accountingInfo/loadBusMachiningHoursList",
            showColumns: true,
            showExport: true,
            pagination: true,                                   // 是否显示分页
            toolbar: '#toolBar',
            uniqueId: "id",
            columns: [
                {
                    checkbox: true,
                    width: '30px'
                },
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {title: '专业', field: 'major', width: '90'},
                {title: '部分', field: 'part', width: '120'},
                {title: '图号', field: 'diagram'},
                {title: '图纸名称', field: 'drawingNo', width: '90'},
                {title: '零件数量', field: 'num', width: '50'},
                {title: '工序', field: 'process', width: '160'},
                {title: '设备型号', field: 'name', width: '160'},
                {title: '工时', field: 'hours', width: '100'},
                {title: '备注', field: 'remark', width: '200'},
                {
                    title: '操作', width: '60',
                    formatter: function (value, row, index,) {
                        let elements = new Array();
                        if (hasP('ver:detail:edit')) {
                            elements.push('<button style="width: 48px" class="btn btn-danger btn-xs" onclick="remove(' + row.id + ')">删除</button>');
                        }
                        return elements.join('');
                    }
                },
            ]
        });
    });

    /**
     * @methodName: remove
     * @description: 删除
     * @param: id
     * @return：
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 15:13
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    function remove(id) {
        js.confirmPost({
            content: "确认要删除当前数据吗？",
            url: ctx + "accountingInfo/removeBusMachiningHoursByIds",
            data: {
                ids: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
</script>
</body>
</html>